package gui;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Image;
import javax.swing.ImageIcon;

/**
 *
 * @author Mariano Zapata
 */
public class DialogoConexionError extends javax.swing.JPanel {

    private int retorno;
    
    public static final int TIPO_CONEXION_PERDIDA= 0;
    public static final int TIPO_CONEXION_FALLIDA= 1;
    public static final int OPCION_SALIR= 2;
    public static final int OPCION_CONFIGURAR= 3;
    
    /** Creates new form DialogoConexionError */
    public DialogoConexionError(int tipo, String motivo)
    {
        initComponents();
        Image icono= new ImageIcon(getClass().getResource("/gui/icono/logo_chico.png")).getImage();
        dialogo.setIconImage(icono);
        dialogo.getContentPane().setLayout(new BorderLayout());
        retorno= -1;
        detalle.setText(motivo);
        switch (tipo)
        {
            case TIPO_CONEXION_PERDIDA:
                mensaje.setText("Se ha perdido la conexión con el Servidor.");
                separador.setVisible(false);
                salir.setVisible(false);
                configuracion.setVisible(false);
                break;
            case TIPO_CONEXION_FALLIDA:
                mensaje.setText("No se ha podido conectar con el Servidor.");
                break;
        }
    }
    
    public int hacerVisible(Component c)
    {
        dialogo.getContentPane().add(this, BorderLayout.CENTER);
        dialogo.pack();
        dialogo.setLocationRelativeTo(c);
        dialogo.setVisible(true);
        dialogo.dispose();
        return retorno;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        dialogo = new javax.swing.JDialog();
        jLabel1 = new javax.swing.JLabel();
        mensaje = new javax.swing.JLabel();
        salir = new javax.swing.JButton();
        configuracion = new javax.swing.JButton();
        separador = new javax.swing.JSeparator();
        jLabel2 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        detalle = new javax.swing.JTextArea();

        dialogo.setTitle("Error de conexión");
        dialogo.setModal(true);
        dialogo.setResizable(false);
        dialogo.addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                cruzDialogo(evt);
            }
        });

        javax.swing.GroupLayout dialogoLayout = new javax.swing.GroupLayout(dialogo.getContentPane());
        dialogo.getContentPane().setLayout(dialogoLayout);
        dialogoLayout.setHorizontalGroup(
            dialogoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );
        dialogoLayout.setVerticalGroup(
            dialogoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 300, Short.MAX_VALUE)
        );

        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gui/icono/servidor_error.png"))); // NOI18N

        mensaje.setFont(new java.awt.Font("Tahoma", 1, 11));
        mensaje.setForeground(java.awt.Color.red);
        mensaje.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        mensaje.setText("Se ha perdido la conexión con el Servidor.");

        salir.setText("Salir");
        salir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                salir(evt);
            }
        });

        configuracion.setText("Configuración");
        configuracion.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                configuracion(evt);
            }
        });

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel2.setText("Detalle:");

        detalle.setColumns(20);
        detalle.setEditable(false);
        detalle.setFont(new java.awt.Font("Monospaced", 0, 11)); // NOI18N
        detalle.setLineWrap(true);
        detalle.setRows(5);
        detalle.setWrapStyleWord(true);
        jScrollPane1.setViewportView(detalle);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(mensaje, javax.swing.GroupLayout.DEFAULT_SIZE, 288, Short.MAX_VALUE))
                    .addComponent(separador, javax.swing.GroupLayout.DEFAULT_SIZE, 342, Short.MAX_VALUE)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 342, Short.MAX_VALUE)
                    .addComponent(jLabel2)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(configuracion)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(salir)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(mensaje)
                    .addComponent(jLabel1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(separador, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(salir)
                    .addComponent(configuracion))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void salir(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_salir
        retorno= OPCION_SALIR;
        dialogo.setVisible(false);
    }//GEN-LAST:event_salir

    private void configuracion(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_configuracion
        retorno= OPCION_CONFIGURAR;
        dialogo.setVisible(false);
    }//GEN-LAST:event_configuracion

    private void cruzDialogo(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_cruzDialogo
        this.salir(null);
    }//GEN-LAST:event_cruzDialogo

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton configuracion;
    private javax.swing.JTextArea detalle;
    private javax.swing.JDialog dialogo;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel mensaje;
    private javax.swing.JButton salir;
    private javax.swing.JSeparator separador;
    // End of variables declaration//GEN-END:variables
}
